

var NvgRefineSearch =
{
    TimeDelay: 100,
    listEstateFolState: [],
    LoadTinhThanh: function () {

        var url = pathClientAjax + "services/formsearchhandler.aspx?act=loadtt&d=" + (new Date()).getTime();
        $.post(url, {},
			function (data) {
			    NvgRefineSearch.TaoStateList(data.lst, "divStateRfs", "txtStateID", "state");
			    if ($('#txtStateID').val() != "") {
			        NvgRefineSearch.ShowTextTopSelect("hrfStateRfs", "iptStateRfs", $('#txtStateText').val());
			    }
			}
		, 'json');
    },
    LoadTinhThanhF: function () {
        var url = pathClientAjax + "services/formsearchhandler.asmx/LoadStateRegionRfsF";
        $.post(url, {},
			function (data) {
			    NvgRefineSearch.TaoList(data.lst, "divStateRfsF", "txtStateID", "state");
			    NvgRefineSearch.SetValueF("divStateRfsF", $('#txtStateID').val());
			}
		, 'json');
    },
    LoadQuanHuyen: function (st, textTinhThanh_) {
        $('#divDropState').hide();
        $('#txtStateText').val(textTinhThanh_);
        // $('#txtSuburb').val("");

        $('#txtStateID').val(st);
        var url = pathClientAjax + "services/formsearchhandler.asmx/LoadSuburb";
        $.post(url, { st: st },
			function (data) {
			    lstSuburb = data.lst;
			    NvgRefineSearch.TaoListMuti(data.lst, 'divSuburb', 'txtSuburb', "suburb");
			    NvgRefineSearch.SetValueF("divSuburb", $('#txtSuburb').val());
			}
		, 'json');
    },
    LoadQuanHuyenF: function () {
        var url = pathClientAjax + "services/formsearchhandler.asmx/LoadSuburb";
        $.post(url, { st: $('#txtStateID').val() },
			function (data) {
			    lstSuburb = data.lst;
			    NvgRefineSearch.TaoListMuti(data.lst, 'divSuburbRfsF', 'txtSuburb', "suburbF");
			    NvgRefineSearch.SetValueF("divSuburbRfsF", $('#txtSuburb').val());
			}
		, 'json');
    },
    LoadLoaiBDSFolTranClass: function (val_) {
        // document.getElementById('txtProClass').value = "";                
        $('#txtPropertyType').val("");
        $('#txtPropertyTypeTextRfs').val("");
        var url = pathClientAjax + "services/formsearchhandler.asmx/LoadClasProFolTran";
        $.post(url, { tc: val_ },
			function (data) {
			    if (data.getElementsByTagName("string")[0].childNodes[0] != undefined) {
			        $('#divLoaiBDS').html(data.getElementsByTagName("string")[0].childNodes[0].nodeValue);

			        $('#divLoaiKieuBDS input:checkbox').attr("disabled", "true");

			        listEstateFolState = [];
			        if ($('#txtSuburb').val() != "" && $('#txtStateID').val() != "") {
			            LoadEstateFST($('#txtStateID').val());
			        }
			    }

			    //			    $('#divLoaiBDSRfs').html(data);
			    //			    $('#divLoaiKieuBDSRfs input:checkbox').attr("disabled", "true");

			    //			    NvgRefineSearch.ShowTextTopSelect("hrfLoaiBDSRfs", "iptLoaiBDSRfs", "");

			    //			    NvgRefineSearch.listEstateFolState = [];
			}
		);
			LoadLoaiBDSFolTranClassUrl(val_);
    },
    LoadLoaiBDSFolTranClassDefault: function (val_) {
        var url = pathClientAjax + "services/formsearchhandler.asmx/LoadClasProFolTran";
        $.post(url, { tc: val_ },
			    function (data) {
			        if (data.getElementsByTagName("string")[0].childNodes[0] != undefined) {
			            $('#divLoaiBDS').html(data.getElementsByTagName("string")[0].childNodes[0].nodeValue);

			            $('#divLoaiKieuBDS input:checkbox').attr("disabled", "true");

			            listEstateFolState = [];
			            if ($('#txtSuburb').val() != "" && $('#txtStateID').val() != "") {
			                LoadEstateFST($('#txtStateID').val());
			            }
			        }

			        //			    $('#divLoaiBDSRfs').html(data);
			        //			    $('#divLoaiKieuBDSRfs input:checkbox').attr("disabled", "true");

			        //			    NvgRefineSearch.ShowTextTopSelect("hrfLoaiBDSRfs", "iptLoaiBDSRfs", "");

			        //			    NvgRefineSearch.listEstateFolState = [];
			    }
		    );
			    LoadLoaiBDSFolTranClassUrl(val_);
    },
    LoadLoaiBDSJs: function () {
        var url = pathClientAjax + "services/formsearchhandler.asmx/LoadLoaiBDSJson";
        $.post(url, { tranClass_: $('#txtTranClass').val() },
			function (data) {
			    NvgRefineSearch.TaoList(data.lst, 'divLoaiBDSRfsF', 'txtProClass', "lbds");
			    NvgRefineSearch.SetValueF("divLoaiBDSRfsF", $('#txtProClass').val());
			}
		, 'json');
    },
    LoadKieuBDSJs: function () {
        var url = pathClientAjax + "services/formsearchhandler.asmx/LoadKieuBDS";
        $.post(url, { id_: $('#txtProClass').val() },
			function (data) {
			    NvgRefineSearch.TaoListMuti(data.lst, 'divKieuBDSRfsF', 'txtPropertyType', "kbds");
			    NvgRefineSearch.SetValueF("divKieuBDSRfsF", $('#txtPropertyType').val());
			}
		, 'json');
    },
    LoadKieuBDSRfs: function () {
        var url = pathClientAjax + "services/formsearchhandler.asmx/ShowKBDSRefineSearch";
        $.post(url, { pc_: $('#txtProClass').val(), kbds_: $('#txtPropertyType').val(), kbdsTxt_: $('#txtPropertyTypeTextRfs').val() },
			    function (data) {
			        if (data.getElementsByTagName("string")[0].childNodes[0] != undefined) {
			            $('#divKieuBDSRfs').html(data.getElementsByTagName("string")[0].childNodes[0].nodeValue);
			            NvgRefineSearch.SetValueF("divKieuBDSRfs", $('#txtPropertyType').val());
			        }
			    }
		    );
        this.LoadKieuBDSUrl();
    },
    LoadKieuBDSUrl: function () {
        var url = pathClientAjax + "services/formsearchhandler.asmx/ShowKBDSRightSearchUrl";
        $.post(url, { pc_: $('#txtProClass').val() },
			    function (data) {
			        lstKieuBds = data.lst;
			    }
		    , 'json');
    },
    LoadLoaiBDSFolTranClass2: function (val_) {
        var pc__ = document.getElementById('txtProClass').value;
        var pctxt__ = document.getElementById('txtProClassTextRfs').value;

        var url = pathClientAjax + "services/formsearchhandler.aspx?act=loadlbdsftc&d=" + (new Date()).getTime();
        $.post(url, { tc: val_ },
			function (data) {
			    $('#divLoaiBDSRfs').html(data);

			    //if (document.getElementById("txtPropertyType").value != "") pctxt__ = $("#txtPropertyTypeTextRfs").val();

			    ChonLoaiBDSNew1(pc__, pctxt__);

			    $('#rdoLoaiBds_' + pc__).attr("checked", "true");

			    if ($('#txtTranClassRfs').val() == "sale") $('#rdoBanRfs').attr("checked", "true");
			    else if ($('#txtTranClassRfs').val() == "rent") $('#rdoChoThueRfs').attr("checked", "true");

			    // 			    if (document.getElementById("txtPropertyType").value != "") {
			    // 			        $('#ullbds_' + pc__ + ' input:checkbox').each(function () {
			    // 			            if (NvgRefineSearch.CheckStringInListString(this.value, document.getElementById("txtPropertyType").value)) {
			    // 			                this.checked = true;
			    // 			            }
			    // 			        });
			    // 			    }
			}
		);
    },
    LoadEstate: function (stateid) {
        if (stateid == "") return;

        var url = pathClientAjax + "services/FormSearchHandler.aspx?act=loaddarfs&d=" + (new Date()).getTime();
        var pars = {
            eid: $("#txtEstate").val(),
            en: $("#txtEstateTextRfs").val(),
            sb: $("#txtSuburb").val(),
            st: stateid,
            tc: $('#txtTranClassRfs').val(),
            pc: $('#txtProClass').val()
        };
        $.post(url, pars,
			function (data) {
			    $('#divEstateRfs').html(data);
			}
		);
    },
    LoadEstateF: function () {
        var stateid = $('#txtStateID').val();
        if (stateid == "") return;

        var url = pathClientAjax + "services/FormSearchHandler.asmx/LoadEstate";
        $.post(url, { suburb: $("#txtSuburb").val(), stateid: stateid, ttype: $('#txtTranClass').val(), ptype: $('#txtProClass').val() },
			function (data) {
			    lstDuAn = data.lst;
			    NvgRefineSearch.TaoListMuti(data.lst, "divEstateRfsF", "txtEstate", "estate");
			    NvgRefineSearch.SetValueF("divEstateRfsF", $('#txtEstate').val());
			}
		, 'json');
    },
    LoadPx: function () {
        if ($("#txtSuburb").val() == "") {
            $('#divPhuongXaRfs').html("Bạn cần chọn quận/huyện");
            return;
        };
        var url = pathClientAjax + "services/FormSearchHandler.asmx/ShowPhuongXa";
        var pars = {
            wid: $("#txtWardIDRfs").val(),
            wn: $("#txtWardTextRfs").val(),
            sb: $("#txtSuburb").val()
        };
        $.post(url, pars,
			function (data) {
			    lstPhuong = data.lst;
			    NvgRefineSearch.TaoListMuti(data.lst, "divPhuongXaRfs", "txtWardIDRfs", "phuong");
			    //			    if (data.getElementsByTagName("string")[0].childNodes[0] != undefined) {
			    //			        $('#divPhuongXaRfs').html(data.getElementsByTagName("string")[0].childNodes[0].nodeValue);
			    //			    }
			}, 'json'
		);
    },
    LoadPxF: function () {
        if ($("#txtSuburb").val() == "") {
            $('#divPxRfsF').html("Bạn cần chọn quận/huyện");
            return;
        }
        var url = pathClientAjax + "services/formsearchhandler.asmx/LoadWardJson";
        $.post(url, { _suburbID: $('#txtSuburb').val() },
			function (data) {
			    NvgRefineSearch.TaoListMuti(data.lst, 'divPxRfsF', 'txtWardIDRfs', "ward");
			    NvgRefineSearch.SetValueF("divPxRfsF", $('#txtWardIDRfs').val());
			}
		, 'json');
    },
    LoadDuong: function () {
        if ($("#txtSuburb").val() == "") {
            $('#divDuongRfs').html("Bạn cần chọn quận/huyện");
            return
        };

        var url = pathClientAjax + "services/FormSearchHandler.asmx/ShowDuongRfs";
        var pars = {
            did: $("#txtStreetIDRfs").val(),
            dn: $("#txtStreetTextRfs").val(),
            sb: $("#txtSuburb").val()
        };
        $.post(url, pars,
			function (data) {
			    if (data.getElementsByTagName("string")[0].childNodes[0] != undefined) {
			        $('#divDuongRfs').html(data.getElementsByTagName("string")[0].childNodes[0].nodeValue);
			    }
			}
		);
    },
    LoadDuongF: function () {
        if ($("#txtSuburb").val() == "") {
            $('#divDuongRfsF').html("Bạn cần chọn quận/huyện");
            return;
        }

        var url = pathClientAjax + "services/formsearchhandler.asmx/LoadDuongJson";
        $.post(url, { _suburbID: $('#txtSuburb').val() },
			function (data) {
			    NvgRefineSearch.TaoListMuti(data.lst, 'divDuongRfsF', 'txtStreetIDRfs', "street");
			    NvgRefineSearch.SetValueF("divDuongRfsF", $('#txtStreetIDRfs').val());
			}
		, 'json');
    },
    LoadGiaRFS: function () {
        var tc = $('#txtTranClass').val();
        var pc = $('#txtProClass').val();
        var url = pathClientAjax + "services/formsearchhandler.asmx/LoadGiaRefineSearch";
        $.post(url, { tc: tc, pc: pc },
			function (data) {
			    $('#divKhoangGiaRfs').html(data);
			}
		);
    },
    LoadGiaF: function () {
        var tc = $('#txtTranClass').val();
        var pc = $('#txtProClass').val();
        var url = pathClientAjax + "services/formsearchhandler.asmx/LoadGiaFormSearch";
        $.post(url, { tc_: tc, pc_: pc },
			function (data) {
			    NvgRefineSearch.TaoList(data.lst, "divGiaRfsF", "txtGia", "gia");
			    NvgRefineSearch.SetValueGiaF("divGiaRfsF", $('#txtGia').val(), "gia");
			}
		, 'json');
    },
    LoadDtttF: function () {
        var url = pathClientAjax + "services/formsearchhandler.asmx/LoadDienTichRfsf";
        $.post(url, {},
			    function (data) {
			        NvgRefineSearch.TaoList(data.lst, "divDtRfsF", "txtDienTich", "dt");
			        NvgRefineSearch.SetValueGiaF("divDtRfsF", $('#txtDienTich').val(), "dt");
			    }
		    , 'json');
    },
    LoadDtnF: function () {
        var url = pathClientAjax + "services/formsearchhandler.asmx/LoadDuongTruocNha";
        $.post(url, {},
			    function (data) {
			        NvgRefineSearch.TaoList(data.lst, "divDtnRfsF", "txtDTNRfs", "dtn");
			        NvgRefineSearch.SetValueGiaF("divDtnRfsF", $('#txtDTNRfs').val(), "dtn");
			    }
		    , 'json');
    },
    LoadKtmtF: function () {
        var url = pathClientAjax + "services/formsearchhandler.asmx/LoadKichThuotMatTien";
        $.post(url, {},
			    function (data) {
			        NvgRefineSearch.TaoList(data.lst, "divKtmtRfsF", "txtKTMTRfs", "ktmt");
			        NvgRefineSearch.SetValueGiaF("divKtmtRfsF", $('#txtKTMTRfs').val(), "ktmt");
			    }
		    , 'json');
    },
    LoadHuongF: function () {
        var url = pathClientAjax + "services/formsearchhandler.asmx/LoadHuongJson";
        $.post(url, {},
			function (data) {
			    NvgRefineSearch.TaoListMuti(data.lst, "divHuongRfsF", "txtHuongIDRfs", "huong");
			    NvgRefineSearch.SetValueF("divHuongRfsF", $('#txtHuongIDRfs').val());
			}
		, 'json');
    },
    LoadPhapLiF: function () {
        var url = pathClientAjax + "services/formsearchhandler.asmx/LoadPhapLiJson";
        $.post(url, {},
			function (data) {
			    NvgRefineSearch.TaoListMuti(data.lst, "divPhapLiRfsF", "txtPhapLiIDRfs", "phapli");
			    NvgRefineSearch.SetValueF("divPhapLiRfsF", $('#txtPhapLiIDRfs').val());
			}
		, 'json');
    },
    CheckStringInListString: function (s, sl) {
        var ar = sl.split(',');
        for (var i = 0; i < ar.length; i++) {
            if (s == ar[i]) return true;
        }
        return false;
    },
    TaoStateList: function (lll, divid, hdf, key_) {
        if (lll != null && lll != "") {
            var tpl__ = "";
            var tplS__ = "";
            tpl__ = $.template("<li><a href=\"javascript:NvgRefineSearch.LoadQuanHuyen('${eValue}','${eName}');$('#txtStreetIDRfs').val('');$('#txtWardIDRfs').val('');$('#divPhuongXaRfs').html('');$('#divDuongRfs').html('');strQuanHuyen='';WriteTextCondition();\">${eName}</a></li>");
            tplS__ = $.template("<li><a href=\"javascript:NvgRefineSearch.LoadQuanHuyen('${eValue}','${eName}');WriteTextCondition();$('#txtStreetIDRfs').val('');$('#txtWardIDRfs').val('');$('#divPhuongXaRfs').html('');$('#divDuongRfs').html('');strQuanHuyen='';WriteTextCondition();\"><span>${eName}</span></a></li>");
            $('#divStateN').append("<li class=\"header\">MIỀN BẮC</li>");
            $('#divStateM').append("<li class=\"header\">MIỀN TRUNG</li>");
            $('#divStateS').append("<li class=\"header\">MIỀN NAM</li>");
            for (var i = 0; i < lll.length; i++) {
                var eID = lll[i].s1;
                var eName = lll[i].s2;
                var eRegion = lll[i].s3;
                if (eRegion == "1") {

                    if (nvgUtils.CheckSplitValue(eID, BigProvinces, ",")) {
                        $('#divStateN').append(tplS__, { eValue: eID, eName: eName, eHdf: hdf });
                    }
                    else {
                        $('#divStateN').append(tpl__, { eValue: eID, eName: eName, eHdf: hdf });
                    }
                }
                if (eRegion == "2") {
                    if (nvgUtils.CheckSplitValue(eID, BigProvinces, ",")) {
                        $('#divStateM').append(tplS__, { eValue: eID, eName: eName, eHdf: hdf });
                    }
                    else {
                        $('#divStateM').append(tpl__, { eValue: eID, eName: eName, eHdf: hdf });
                    }
                }
                if (eRegion == "3") {
                    if (nvgUtils.CheckSplitValue(eID, BigProvinces, ",")) {
                        $('#divStateS').append(tplS__, { eValue: eID, eName: eName, eHdf: hdf });
                    }
                    else {
                        $('#divStateS').append(tpl__, { eValue: eID, eName: eName, eHdf: hdf });
                    }
                }
            }
        }
    },
    TaoListEstate: function (lll, divid) {
        $('#' + divid).html("");
        if (lll != "" && lll != null) {
            $('#' + divid).append("<li><a href=\"javascript:;\" onclick=\"$('#divEstateRfs input:checkbox').removeAttr('checked'); getDataEstate();\">Xóa tất cả</li>");
            var tpl__ = $.template("<li><a href=\"javascript:;\"><input type=\"checkbox\" value=\"${eID}\" title=\"${eName}\" onclick=\"getDataEstate();\" >${eName} <span>(${eCount})</span></a></li>");
            for (var i = 0; i < lll.length; i++) {
                if (lll[i].s4 != "0") {
                    var eID = lll[i].s1;
                    var eName = lll[i].s2;
                    var eSuburb = lll[i].s3;
                    var eCount = lll[i].s4;

                    $('#' + divid).append(tpl__, { inputId: i, eID: eID, eName: eName, eCount: eCount });
                }
            }
        }
    },
    TaoListMuti: function (lll, divid, hdf, key_) {
        $('#' + divid).html("");
        if (lll != "" && lll != null) {
            var tpl__ = "";

            if (key_ == "estate") {
                tpl__ = $.template("<li><a href=\"javascript:;\"><input type=\"checkBox\" value=\"${eValue}\" title=\"${eName}\" onclick=\"NvgRefineSearch.SetHdfF('divEstateRfsF','txtEstate','spnDaRfs');\"> ${eName} (${eCount})</li>");
            }
            else if (key_ == "suburb")
                tpl__ = $.template("<li><a href=\"javascript:;\" ><input type=\"checkBox\" value=\"${eValue}\" title=\"${eName}\" onclick=\"SetTextSuburb();LoadEstateFST($('#txtStateID').val());WriteTextCondition();NvgRefineSearch.LoadPx();\" id=\"cld_${eValue}\" /> ${eName}</a></li>");
            //tpl__ = $.template("<li><input type=\"checkBox\" value=\"${eValue}\" title=\"${eName}\" onclick=\"NvgRefineSearch.SetHdfF('divSuburb','txtSuburb','spnQhRfs');\"> ${eName}</li>");
            else if (key_ == "suburbF")
                tpl__ = $.template("<li><a href=\"javascript:;\"><input type=\"checkBox\" value=\"${eValue}\" title=\"${eName}\" onclick=\"NvgRefineSearch.SetHdfF('divSuburbRfsF','txtSuburb','spnQhRfs');\"> ${eName}</a></li>");
            else if (key_ == "ward")
                tpl__ = $.template("<li><a href=\"javascript:;\"><input type=\"checkBox\" value=\"${eValue}\" title=\"${eName}\" onclick=\"NvgRefineSearch.SetHdfF('divPxRfsF','txtWardIDRfs','spnPxRfs');\"> ${eName}</a></li>");
            else if (key_ == "street")
                tpl__ = $.template("<li><a href=\"javascript:;\"><input type=\"checkBox\" value=\"${eValue}\" title=\"${eName}\" onclick=\"NvgRefineSearch.SetHdfF('divDuongRfsF','txtStreetIDRfs','spnDRfs');\"> ${eName}</a></li>");
            else if (key_ == "huong")
                tpl__ = $.template("<li><a href=\"javascript:;\"><input type=\"checkBox\" value=\"${eValue}\" title=\"${eName}\" onclick=\"NvgRefineSearch.SetHdfF('divHuongRfsF','txtHuongIDRfs','spnHRfs');\"> ${eName}</a></li>");
            else if (key_ == "phapli")
                tpl__ = $.template("<li><a href=\"javascript:;\"><input type=\"checkBox\" value=\"${eValue}\" title=\"${eName}\" onclick=\"NvgRefineSearch.SetHdfF('divPhapLiRfsF','txtPhapLiIDRfs','spnPlRfs');\"> ${eName}</a></li>");
            else if (key_ == "kbds")
                tpl__ = $.template("<li><a href=\"javascript:;\"><input type=\"checkBox\" value=\"${eValue}\" title=\"${eName}\" onclick=\"NvgRefineSearch.SetHdfF('divKieuBDSRfsF','txtPropertyType','spnKbdsRfs');\"> ${eName}</a></li>");
            else if (key_ == "phuong")
                tpl__ = $.template("<p><a href=\"javascript:;\" onclick=\"NvgRefineSearch.ChgClsClk(this);NvgRefineSearch.SetValHdf('ward','${eValue}');\"> ${eName}</a></p>");

            if (key_ == "phuong") {
                if (lll.length > 0) {
                    $('#' + divid).append("<h5>Phường/Xã</h5>");
                    for (var i = 0; i < lll.length; i++) {
                        var eID = lll[i].s1;
                        var eName = lll[i].s2;
                        // var nameKhongDau = lll[i].s3;
                        $('#' + divid).append(tpl__, { eValue: eID, eName: eName });
                    }
                    $('#' + divid).append("<p class=\"otherOption\"><a onclick=\"NvgRefineSearch.ShowPopupTimKiem('ahrfPxRfs','ward');\" href=\"javascript:;\">Lựa chọn khác</a></p>");
                }
            }
            else if (key_ == "estate") {
                var _suburb = $('#txtSuburb').val();
                for (var i = 0; i < lll.length; i++) {
                    var eID = lll[i].s1;
                    var eName = lll[i].s2;
                    var eCount = lll[i].s3;
                    if (NvgRefineSearch.CheckStringInListString(eQuan, _suburb))
                        $('#' + divid).append(tpl__, { eValue: eID, eName: eName, eCount: eCount });
                }
            }
            else {
                for (var i = 0; i < lll.length; i++) {
                    var eID = lll[i].s1;
                    var eName = lll[i].s2;

                    $('#' + divid).append(tpl__, { eValue: eID, eName: eName, eHdf: hdf });
                }
            }
        }
    },
    TaoList: function (lll, divid, hdf, key_) {
        $('#' + divid).html("");
        if (lll != "" && lll != null) {
            var tpl__ = "";
            if (key_ == "state") {
                tpl__ = $.template("<li><a href=\"javascript:;\"><input name=\"rdoTTRfsF\" type=\"radio\" value=\"${eValue}\" title=\"${eName}\" onclick=\"NvgRefineSearch.SetTinhThanhF('${eValue}','${eName}');\"> ${eName}</a></li>");
            }
            else if (key_ == "gia") {
                tpl__ = $.template("<li><a href=\"javascript:;\"><input type=\"radio\" name=\"rdoGia\" onclick=\"NvgRefineSearch.BindHdfFreeRdo('${eValue}','gia','${eName}');\"> ${eName}</a></li>");
            }
            else if (key_ == "lbds")
                tpl__ = $.template("<li><a href=\"javascript:;\"><input type=\"radio\" name=\"rdoLoaiBDS\" value=\"${eValue}\" onclick=\"$('#txtProClass').val('${eValue}');$('#txtPropertyType').val('');NvgRefineSearch.LoadKieuBDSJs();\"> ${eName}</a></li>");
            else if (key_ == "dt") {
                tpl__ = $.template("<li><a href=\"javascript:;\"><input type=\"radio\" name=\"rdoDt\" onclick=\"NvgRefineSearch.BindHdfFreeRdo('${eValue}','dt','${eName}');\"> ${eName}</a></li>");
            }
            else if (key_ == "dtn") {
                tpl__ = $.template("<li><a href=\"javascript:;\"><input type=\"radio\" name=\"rdoDtn\" onclick=\"NvgRefineSearch.BindHdfFreeRdo('${eValue}','dtn','${eName}');\"> ${eName}</a></li>");
            }
            else if (key_ == "ktmt") {
                tpl__ = $.template("<li><a href=\"javascript:;\"><input type=\"radio\" name=\"rdoKtmt\" onclick=\"NvgRefineSearch.BindHdfFreeRdo('${eValue}','ktmt','${eName}');\"> ${eName}</a></li>");
            }

            for (var i = 0; i < lll.length; i++) {
                var eID = lll[i].s1;
                var eName = lll[i].s2;

                $('#' + divid).append(tpl__, { eValue: eID, eName: eName, eHdf: hdf });
            }
        }
    },
    ClearAllPT: function () {
        document.getElementById('txtPropertyType').value = "";
        $('#divLoaiKieuBDSRfs input:checkbox').removeAttr("checked");
        $('#divLoaiKieuBDSRfs input:radio').removeAttr("checked");
        $('#divLoaiKieuBDSRfs input:checkbox').attr("disabled", "true");
        $('#txtProClass').val("");

        document.getElementById('txtProClassTextRfs').value = "";

        this.ShowTextTopSelect("hrfLoaiBDSRfs", "iptLoaiBDSRfs", "");

    },
    SetTinhThanh: function (stid, stName) {
        NvgRefineSearch.ShowTextTopSelect('hrfStateRfs', 'iptStateRfs', stName);
        //NvgRefineSearch.LoadQuanHuyen('${eValue}','${eName}');
        $('#txtStateID').val(stid);
        $('#txtStateText').val(stName);
        $('#txtSuburb').val("");
        $('#divDropStateRfs').hide();
    },
    SetTinhThanhF: function (stid, stName) {
        //NvgRefineSearch.ShowTextTopSelect('hrfStateRfs', 'iptStateRfs', stName);
        $('#txtStateID').val(stid);
        //$('#txtStateText').val(stName);
        $('#txtSuburb').val("");
        $('#spnQhRfs').html("");
        $('#spnDaRfs').html("");
        $('#spnPxRfs').html("");
        $('#spnDRfs').html("");
        $('#spnTtRfs').html("(" + stName + ")");
    },
    SelectAllTinhThanh: function () {
        $('#txtStateID').val("");
        $('#txtSuburb').val("");
        $('#iptStateRfs').hide();
        $('#hrfStateRfs').show();
        $('#divSuburbRfs').html("");
        $('#txtStateText').val("");
    },
    ShowTextTopSelect: function (hrf, ipt, con) {
        if (con == "") {
            $('#' + ipt).hide();
            $('#' + hrf).show();
            $('#' + ipt).val("");
        }
        else {
            $('#' + hrf).hide();
            $('#' + ipt).show();
            $('#' + ipt).val(con);
        }
    },
    ShowPopupTimKiem: function (ahrfID_, _loai) {
        var url = pathClientAjax + "services/formsearchhandler.asmx/LoadRefineSearchFull";
        $.post(url, {},
			function (data) {
			    $('#divFullSearch').html(data);
			    $('#divFullSearch').centerInClient({ minY: 1 });
			    $('#divFullSearch').width("700px");
			    NvgRefineSearch.CountAllF();
			    NvgRefineSearch.ShowLgdRfs(ahrfID_, _loai);
			    $('#divFullSearch').show();
			    NvgRefineSearch.LuuDieuKien();
			}
		);
    },
    ShowLgdRfs: function (ahrfID_, _loai) {
        $('.colMenu li a').removeClass("current");
        //document.getElementById(ahrfID_).className = "current";
        $('#' + ahrfID_ + " a").addClass("current");

        $('.colContent div').hide();
        switch (_loai) {
            case "lgd":
                $('#divTitleRfsF').html("Loại hình BĐS");
                if ($('#txtTranClass').val() == "sale") $('#rdoBanRfsF').attr("checked", "true");
                else if ($('#txtTranClass').val() == "rent") $('#rdoChoThueRfsF').attr("checked", "true");
                $('#div_lgdrfs').show();

                this.LoadLoaiBDSJs();
                $('#div_lbdsrfs').show();

                this.LoadKieuBDSJs();
                $('#div_kbdsrfs').show();
                break;
            case "lbds":
                $('#divTitleRfsF').html("Loại bất động sản");
                this.LoadLoaiBDSJs();
                $('#div_lbdsrfs').show();
                break;
            case "state":
                $('#divTitleRfsF').html("Tỉnh/Thành Phố");
                this.LoadTinhThanhF();
                $('#div_ttrfs').show();
                break;
            case "suburb":
                $('#divTitleRfsF').html("Quận/Huyện");
                this.LoadQuanHuyenF();
                $('#div_qhrfs').show();
                break;
            case "cbHomeClass":
                $('#divTitleRfsF').html("Kiểu bất động sản");
                this.LoadKieuBDSJs();
                $('#div_kbdsrfs').show();
                break;
            case "cbMinPrice-cbMaxPrice":
                $('#divTitleRfsF').html("Khoảng giá");
                this.LoadGiaF();
                $('#div_grfs div').show();
                $('#div_grfs').show();
                break;
            case "cbEstate":
                $('#divTitleRfsF').html("Dự án ở " + $('#txtStateText').val());
                this.LoadEstateF();
                $('#div_darfs').show();
                break;
            case "ward":
                $('#divTitleRfsF').html("Phường/Xã ở " + $('#txtStateText').val());
                this.LoadPxF();
                $('#div_pxrfs').show();
                break;
            case "streetid":
                $('#divTitleRfsF').html("Đường ở " + $('#txtStateText').val());
                this.LoadDuongF();
                $('#div_drfs').show();
                break;
            case "cbAspect":
                $('#divTitleRfsF').html("Hướng nhà đất");
                this.LoadHuongF();
                $('#div_hrfs').show();
                break;
            case "cbOwnerType":
                $('#divTitleRfsF').html("Tình trạng pháp lý");
                this.LoadPhapLiF();
                $('#div_plrfs').show();
                break;
            case "dttt":
                $('#divTitleRfsF').html("Diện tích đất tối thiểu");
                $('#txtDienTichTuf').val($('#txtDienTichTu').val());
                $('#txtDienTichDenf').val($('#txtDienTichDen').val());
                this.LoadDtttF();
                $('#div_dtttrfs div').show();
                $('#div_dtttrfs').show();
                break;
            case "dtn":
                $('#divTitleRfsF').html("Đường trước nhà");
                $('#txtDtnMinRfsf').val($('#txtDtnMinRfs').val());
                $('#txtDtnMaxRfsf').val($('#txtDtnMaxRfs').val());
                this.LoadDtnF();
                $('#div_dtnrfs div').show();
                $('#div_dtnrfs').show();
                break;
            case "ktmt":
                $('#divTitleRfsF').html("Kích thước mặt tiền");
                $('#txtKtmtMinRfsf').val($('#txtKtmtMinRfs').val());
                $('#txtKtmtMaxRfsf').val($('#txtKtmtMaxRfs').val());
                this.LoadKtmtF();
                $('#div_ktmtrfs div').show();
                $('#div_ktmtrfs').show();
                break;
            case "dtqc":
                $('#divTitleRfsF').html("Đặc tính");

                if ($('#txtTabRfs').val() == "rv") {
                    $('#rdoDTTatcaF').attr("checked", "true");
                    $('#spnDtRfs').html("(Tất cả BĐS)");
                }
                else if ($('#txtTabRfs').val() == "ag") {
                    $('#rdoDTVipF').attr("checked", "true");
                    $('#spnDtRfs').html("(BĐS nổi bật)");
                }
                else if ($('#txtTabRfs').val() == "cc") {
                    $('#rdoDTChinhChuF').attr("checked", "true");
                    $('#spnDtRfs').html("(Chính chủ)");
                }
                else if ($('#txtTabRfs').val() == "ch") {
                    $('#rdoDTIsImgF').attr("checked", "true");
                    $('#spnDtRfs').html("(BĐS có hình)");
                }

                $('#div_iirfs').show();
                break;
            default:
        }
        $('#divTitleRfsF').show();
    },
    SetToggle: function (_loai) {
        switch (_loai) {
            case "suburb":
                if ($('#txtSuburb').val() == "") {
                    $('#divQuanHuyenRfs').toggle();
                    this.ChangeCssToggle('spnTgQh');
                }
                break;
            case "cbHomeClass":
                if ($('#txtPropertyType').val() == "") {
                    $('#divKieuBDSRfs').toggle();
                    this.ChangeCssToggle('spnTgKbds');
                }
                break;
            case "cbMinPrice-cbMaxPrice":
                if ($('#txtGiaTu').val() == "" && $('#txtGiaDen').val() == ""
                     && $('#txtGia').val() == "") {
                    $('#divListKhoangGiaRfs').toggle();
                    this.ChangeCssToggle('spnTgG');
                }
                break;
            case "cbEstate":
                if ($('#txtEstate').val() == "") {
                    $('#divEstateRfs').toggle();
                    this.ChangeCssToggle('spnTgDa');
                }
                break;
            case "ward":
                if ($('#txtWardIDRfs').val() == "") {
                    $('#divPhuongXaRfs').toggle();
                    this.ChangeCssToggle('spnTgPx');
                }
                break;
            case "streetid":
                if ($('#txtStreetIDRfs').val() == "") {
                    $('#divDuongRfs').toggle();
                    this.ChangeCssToggle('spnTgD');
                }
                break;
            case "cbAspect":
                if ($('#txtHuongIDRfs').val() == "") {
                    $('#divHuongRfs').toggle();
                    this.ChangeCssToggle('spnTgH');
                }
                break;
            case "cbOwnerType":
                if ($('#txtPhapLiIDRfs').val() == "") {
                    $('#divPhapLiRfs').toggle();
                    this.ChangeCssToggle('spnTgPl');
                }
                break;
            case "dttt":
                if ($('#txtDienTichTu').val() == "" && $('#txtDienTichDen').val() == "" && $('#txtDienTich').val() == "") {
                    $('#divDtttRfs').toggle();
                    this.ChangeCssToggle('spnTgDttt');
                }
                break;
            case "dtn":
                if ($('#txtDtnMinRfs').val() == "" && $('#txtDtnMaxRfs').val() == "" && $('#txtDTNRfs').val() == "") {
                    $('#divDtnRfs').toggle();
                    this.ChangeCssToggle('spnTgDtn');
                }
                break;
            case "ktmt":
                if ($('#txtKtmtMinRfs').val() == "" && $('#txtKtmtMaxRfs').val() == "" && $('#txtKTMTRfs').val() == "") {
                    $('#divKtmtRfs').toggle();
                    this.ChangeCssToggle('spnTgKtmt');
                }
                break;
            case "dactinh":
                if ($('#txtIsImageIDRfs').val() == "" && $('#txtChinhChuRfs').val() == "") {
                    $('#divDacTinhRfs').toggle();
                    this.ChangeCssToggle('spnTgDt');
                }
                break;
            default:
        }
    },
    ChangeCssToggle: function (this_) {
        var __this = document.getElementById(this_);
        if (__this.className == "rlp-x") {
            __this.className = "rlp-a";
        }
        else if (__this.className == "rlp-a") {
            __this.className = "rlp-x";
        }
    },
    BindHdfFreeRdo: function (_value, _loai, _text) {
        var arr_ = _value.split('-');
        if (_loai == "gia") {
            /*
            $('#txtGiaTuF').val(arr_[0]);
            $('#txtGiaDenF').val(arr_[1]);
            */
            $('#spnKgRfs').html("(" + _text + ")");
            $('#txtGia').val(arr_[0] + "-" + arr_[1]);

            $('#txtGiaTuRfsF').val('');
            $('#txtGiaDenRfsF').val('');
            $('#txtGiaTu').val('');
            $('#txtGiaDen').val('');

            $('#dtgf').html("");
            $('#dtdf').html("");
        }
        if (_loai == "dt") {
            $('#txtDienTich').val(arr_[0] + "-" + arr_[1]);

            $('#spnDtttRfs').html("(" + _text + ")");

            $('#txtDienTichTu').val("");
            $('#txtDienTichDen').val("");
            $('#txtDienTichTuRfsf').val("");
            $('#txtDienTichDenRfsf').val("");
        }
        if (_loai == "dtn") {
            $('#txtDTNRfs').val(arr_[0] + "-" + arr_[1]);

            $('#spnDtnRfs').html("(" + _text + ")");

            $('#txtDtnMinRfs').val("");
            $('#txtDtnMaxRfs').val("");
            $('#txtDtnMinRfsf').val("");
            $('#txtDtnMaxRfsf').val("");
        }
        if (_loai == "ktmt") {
            $('#txtKTMTRfs').val(arr_[0] + "-" + arr_[1]);

            $('#spnKtmtRfs').html("(" + _text + ")");

            $('#txtKtmtMinRfs').val("");
            $('#txtKtmtMaxRfs').val("");
            $('#txtKtmtMinRfsf').val("");
            $('#txtKtmtMaxRfsf').val("");
        }
    },
    SetHdfFree: function (id_, value_, divID_) {
        $('#' + divID_ + ' input').removeAttr("checked");
        $('#' + id_).val(value_);

        if (($('#txtGiaTu').val() != "" && $('#txtGiaDen').val() != "") || $('#txtGia').val() != "") {
            $('#spnKgRfs').html("(" + $('#dtgf').html() + " - " + $('#dtdf').html() + ")");
            $('#txtGia').val($('#txtGiaTu').val() + "-" + $('#txtGiaDen').val());
        }
        else $('#spnKgRfs').html("");

        if ($('#txtDienTichTu').val() != "" && $('#txtDienTichDen').val() != "") {
            $('#spnDtttRfs').html("(" + $('#txtDienTichTu').val() + " - " + $('#txtDienTichDen').val() + " m2)");
            $('#txtDienTich').val($('#txtDienTichTu').val() + "-" + $('#txtDienTichDen').val());
        }
        else $('#spnDtttRfs').html("");

        if ($('#txtDtnMinRfs').val() != "" && $('#txtDtnMaxRfs').val() != "") {
            $('#spnDtnRfs').html("(" + $('#txtDtnMinRfs').val() + " - " + $('#txtDtnMaxRfs').val() + " m)");
            $('#txtDTNRfs').val($('#txtDtnMinRfs').val() + "-" + $('#txtDtnMaxRfs').val());
        }
        else $('#spnDtnRfs').html("");

        if ($('#txtKtmtMinRfs').val() != "" && $('#txtKtmtMaxRfs').val() != "") {
            $('#spnKtmtRfs').html("(" + $('#txtKtmtMinRfs').val() + " - " + $('#txtKtmtMaxRfs').val() + " m)");
            $('#txtKTMTRfs').val($('#txtKtmtMinRfs').val() + "-" + $('#txtKtmtMaxRfs').val());
        }
        else $('#spnKtmtRfs').html("");
    },
    ChgClsHvr: function (_this) {
        if (_this.className == "asr-v asr-sd") _this.className = "asr-v asr-sh";
        else if (_this.className == "asr-v asr-nd") _this.className = "asr-v asr-nh";
    },
    ChgClsOut: function (_this) {
        if (_this.className == "asr-v asr-sh") _this.className = "asr-v asr-sd";
        else if (_this.className == "asr-v asr-nh") _this.className = "asr-v asr-nd";
    },
    ChgClsClk: function (_this) {
        if (_this.className == "current") {
            _this.className = "";
        }
        else if (_this.className == "") {
            _this.className = "current";
        }
    },
    ChgClsClkO: function (_this, _divid) {
        if (_this.className == "current") {
            $('#' + _divid + " a").removeClass("current");
        }
        else {
            $('#' + _divid + " a").removeClass("current");
            _this.className = "current";
        }
    },
    ShowButtonGo: function (btnID) {
        $('#' + btnID).show();
    },
    AddElementArr: function (s) {
        var arr = s.split(',');
        var arr1 = [];
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] != "") {
                arr1.push(arr[i]);
            }
        }
        return arr1;
    },
    RemoveElementArr: function (s, _value) {
        var arr = s.split(',');
        var arr1 = [];
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] != _value && arr[i] != "") {
                arr1.push(arr[i]);
            }
        }
        return arr1;
    },
    SetValueF: function (divID_, value_) {
        $('#' + divID_ + ' input').each(function () {
            if (NvgRefineSearch.CheckStringInListString(this.value, value_)) this.checked = true;
        }
		);
    },
    SetValueGiaF: function (divID_, value_, loai_) {
        var flag_ = false;
        $('#' + divID_ + ' input').each(function () {
            if (NvgRefineSearch.CheckStringInListString(this.value, value_)) {
                this.checked = true;
                flag_ = true;
            }
        });

        if (!flag_) {
            if (loai_ == "gia") {
                $('#txtGiaTuRfsF').val(value_.split('-')[0]);
                $('#txtGiaDenRfsF').val(value_.split('-')[1]);
            }
            else if (loai_ == "dt") {
                $('#txtDienTichTuRfsf').val(value_.split('-')[0]);
                $('#txtDienTichDenRfsf').val(value_.split('-')[1]);
            }
            else if (loai_ == "dtn") {
                $('#txtDtnMinRfsf').val(value_.split('-')[0]);
                $('#txtDtnMaxRfsf').val(value_.split('-')[1]);
            }
            else if (loai_ == "ktmt") {
                $('#txtKtmtMinRfsf').val(value_.split('-')[0]);
                $('#txtKtmtMaxRfsf').val(value_.split('-')[1]);
            }
        }
    },
    SetHdfF: function (divID_, hdfID_, spnDemID_) {
        var dem = 0;
        var bien_ = document.getElementById(hdfID_).value;
        document.getElementById(hdfID_).value = "";
        $('#' + spnDemID_).html("");
        $('#' + divID_ + ' input:checkbox').each(function () {
            if (this.checked == true) {
                document.getElementById(hdfID_).value += this.value + ",";
                dem++;
            }
        });
        if (dem != 0)
            $('#' + spnDemID_).html("(Chọn " + dem + ")");
        // kiem tra ko cho quan huyen qua nhiu 
        if (hdfID_ == "txtSuburb") {
            if ($('#txtSuburb').val().split(',').length > 6) {
                alert("Bạn chọn quá nhiều quận/huyện, vui lòng chọn không quá 5");
                // restore lai uncheck
                dem--;
                $('#' + divID_ + ' input:checkbox').removeAttr("checked");
                $('#' + spnDemID_).html("(Chọn " + dem + ")");
                // check lai tu dau
                $('#' + divID_ + ' input:checkbox').each(function () {
                    if (NvgRefineSearch.CheckStringInListString(this.value, bien_)) {
                        this.checked = true;
                    }
                });
                // gan lai gtri dau
                $('#' + hdfID_).val(bien_);
                return false;
            }
        }

    },
    CountLenghtHdfValue: function (hdfValue) {
        var arr__ = trim(hdfValue, ',').split(',');

        return arr__.length;

    },
    CountAllF: function () {
        var _txt = "Chọn ";
        if ($('#txtStateID').val() != "") {
            $('#spnTtRfs').html("(" + $('#txtStateText').val() + ")");
        }
        if ($('#txtSuburb').val() != "") {
            var a = this.CountLenghtHdfValue($('#txtSuburb').val());
            if (a != 0) $('#spnQhRfs').html("(" + _txt + a + ")");
        }
        if ($('#txtEstate').val() != "") {
            var a = this.CountLenghtHdfValue($('#txtEstate').val());
            if (a != 0) $('#spnDaRfs').html("(" + _txt + a + ")");
        }
        if ($('#txtWardIDRfs').val() != "") {
            var a = this.CountLenghtHdfValue($('#txtWardIDRfs').val());
            if (a != 0) $('#spnPxRfs').html("(" + _txt + a + ")");
        }
        if ($('#txtStreetIDRfs').val() != "") {
            var a = this.CountLenghtHdfValue($('#txtStreetIDRfs').val());
            if (a != 0) $('#spnDRfs').html("(" + _txt + a + ")");
        }
        if ($('#txtHuongIDRfs').val() != "") {
            var a = this.CountLenghtHdfValue($('#txtHuongIDRfs').val());
            if (a != 0) $('#spnHRfs').html("(" + _txt + a + ")");
        }
        if ($('#txtPhapLiIDRfs').val() != "") {
            var a = this.CountLenghtHdfValue($('#txtPhapLiIDRfs').val());
            if (a != 0) $('#spnPlRfs').html("(" + _txt + a + ")");
        }
        if ($('#txtPropertyType').val() != "") {
            var a = this.CountLenghtHdfValue($('#txtPropertyType').val());
            if (a != 0) $('#spnKbdsRfs').html("(" + _txt + a + ")");
        }

        if ($('#txtGiaTu').val() != "" && $('#txtGiaDen').val() != "") {
            $('#spnKgRfs').html("(" + $('#dtg').html() + " - " + $('#dtd').html() + ")");
        }
        else if ($('#txtGia').val() != "") {
            $('#spnKgRfs').html("(" + this.ShowGiaText($('#txtGia').val().split('-')[0]) + " - " + this.ShowGiaText($('#txtGia').val().split('-')[1]) + ")");
        }
        else $('#spnKgRfs').html("");

        if ($('#txtDienTichTu').val() != "" && $('#txtDienTichDen').val() != "") {
            $('#spnDtttRfs').html("(" + $('#txtDienTichTu').val() + " - " + $('#txtDienTichDen').val() + " m<sup>2</sup>)");
        }
        else
            if ($('#txtDienTich').val() != "") {
                $('#spnDtttRfs').html("(" + $('#txtDienTich').val().split('-')[0] + " - " + $('#txtDienTich').val().split('-')[1] + " m<sup>2</sup>)");
            }
            else $('#spnDtttRfs').html("");

        if ($('#txtDtnMinRfs').val() != "" && $('#txtDtnMaxRfs').val() != "") {
            $('#spnDtnRfs').html("(" + $('#txtDtnMinRfs').val() + " - " + $('#txtDtnMaxRfs').val() + " m)");
        }
        else
            if ($('#txtDTNRfs').val() != "") {
                $('#spnDtnRfs').html("(" + $('#txtDTNRfs').val().split('-')[0] + " - " + $('#txtDTNRfs').val().split('-')[1] + " m)");
            }
            else $('#spnDtnRfs').html("");

        if ($('#txtKtmtMinRfs').val() != "" && $('#txtKtmtMaxRfs').val() != "") {
            $('#spnKtmtRfs').html("(" + $('#txtKtmtMinRfs').val() + " - " + $('#txtKtmtMaxRfs').val() + " m)");
        }
        else
            if ($('#txtKTMTRfs').val() != "") {
                $('#spnKtmtRfs').html("(" + $('#txtKTMTRfs').val().split('-')[0] + " - " + $('#txtKTMTRfs').val().split('-')[1] + " m)");
            }
            else $('#spnKtmtRfs').html("");

        /* dac tinh quang cao*/

        if ($('#txtTabRfs').val() == "rv") {
            $('#rdoDTTatcaF').attr("checked", "true");
            $('#spnDtRfs').html("(Tất cả BĐS)");
        }
        else if ($('#txtTabRfs').val() == "ag") {
            $('#rdoDTVipF').attr("checked", "true");
            $('#spnDtRfs').html("(BĐS nổi bật)");
        }
        else if ($('#txtTabRfs').val() == "cc") {
            $('#rdoChinhChuF').attr("checked", "true");
            $('#spnDtRfs').html("(Chính chủ)");
        }
        else if ($('#txtTabRfs').val() == "ch") {
            $('#rdoDTIsImgF').attr("checked", "true");
            $('#spnDtRfs').html("(BĐS có hình)");
        }

    },
    JsonOldConDition: {
        state: '', suburb: '', estate: '', ward: '', street: '', huong: '', phapli: '', protype: '', giatu: '', giaden: '', gia: '', dtttt: '', dtttd: '', dt: ''
        , dtnt: '', dtnd: '', dtn: '', ktmtt: '', ktmtd: '', ktmt: '', tab: ''
    },
    LuuDieuKien: function () {
        //if ($('#txtStateID').val() != "") {
        this.JsonOldConDition.state = $('#txtStateID').val();
        // }
        // if ($('#txtSuburb').val() != "") {
        this.JsonOldConDition.suburb = $('#txtSuburb').val();
        //         }
        //         if ($('#txtEstate').val() != "") {
        this.JsonOldConDition.estate = $('#txtEstate').val();
        //         }
        //         if ($('#txtWardIDRfs').val() != "") {
        this.JsonOldConDition.ward = $('#txtWardIDRfs').val();
        //         }
        //         if ($('#txtStreetIDRfs').val() != "") {
        this.JsonOldConDition.street = $('#txtStreetIDRfs').val();
        //         }
        //         if ($('#txtHuongIDRfs').val() != "") {
        this.JsonOldConDition.huong = $('#txtHuongIDRfs').val();
        //         }
        // 
        //         if ($('#txtPhapLiIDRfs').val() != "") {
        this.JsonOldConDition.phapli = $('#txtPhapLiIDRfs').val();
        //         }
        //         if ($('#txtPropertyType').val() != "") {
        this.JsonOldConDition.protype = $('#txtPropertyType').val();
        //         }
        // 
        //         if ($('#txtGiaTu').val() != "" && $('#txtGiaDen').val() != "") {
        this.JsonOldConDition.giatu = $('#txtGiaTu').val();
        this.JsonOldConDition.giaden = $('#txtGiaDen').val();
        //         }
        //         else if ($('#txtGia').val() != "") {
        this.JsonOldConDition.gia = $('#txtGia').val();
        //         }
        // 
        //         if ($('#txtDienTichTu').val() != "" && $('#txtDienTichDen').val() != "") {
        this.JsonOldConDition.dtttt = $('#txtDienTichTu').val();
        this.JsonOldConDition.dtttd = $('#txtDienTichDen').val();
        //         }
        //         else if ($('#txtDienTich').val() != "") {
        this.JsonOldConDition.dt = $('#txtDienTich').val();
        //         }
        // 
        //         if ($('#txtDtnMinRfs').val() != "" && $('#txtDtnMaxRfs').val() != "") {
        this.JsonOldConDition.dtnt = $('#txtDtnMinRfs').val();
        this.JsonOldConDition.dtnd = $('#txtDtnMaxRfs').val();
        //         }
        //         else if ($('#txtDTNRfs').val() != "") {
        this.JsonOldConDition.dtn = $('#txtDTNRfs').val();
        //         }
        // 
        //         if ($('#txtKtmtMinRfs').val() != "" && $('#txtKtmtMaxRfs').val() != "") {
        this.JsonOldConDition.ktmtt = $('#txtKtmtMinRfs').val();
        this.JsonOldConDition.ktmtd = $('#txtKtmtMaxRfs').val();
        //         }
        //         else if ($('#txtKTMTRfs').val() != "") {
        this.JsonOldConDition.ktmt = $('#txtKTMTRfs').val();
        //         }
        // 
        //         if ($('#txtTabRfs').val() != "") 
        this.JsonOldConDition.tab = $('#txtTabRfs').val();

        /* dac tinh quang cao
        if ($('#txtIsImageIDRfs').val() != "" && $('#txtChinhChuRfs').val() != "") {
        $('#spnDtRfs').html('(BĐS có hình, Chính chủ)');
        }
        else if ($('#txtIsImageIDRfs').val() != "") {
        $('#spnDtRfs').html('(BĐS có hình)');
        }
        else if ($('#txtChinhChuRfs').val() != "") {
        $('#spnDtRfs').html('(Chính chủ)');
        }*/
    },
    ResDieuKien: function () {
        //if (this.JsonOldConDition.state != "") {
        $('#txtStateID').val(this.JsonOldConDition.state);
        // }
        //if (this.JsonOldConDition.suburb != "") {
        $('#txtSuburb').val(this.JsonOldConDition.suburb);
        // }
        // if (this.JsonOldConDition.estate != "") {
        $('#txtEstate').val(this.JsonOldConDition.estate);
        // }
        // if (this.JsonOldConDition.ward != "") {
        $('#txtWardIDRfs').val(this.JsonOldConDition.ward);
        // }
        // if (this.JsonOldConDition.street != "") {
        $('#txtStreetIDRfs').val(this.JsonOldConDition.street);
        //}
        // if (this.JsonOldConDition.huong != "") {
        $('#txtHuongIDRfs').val(this.JsonOldConDition.huong);
        // }
        // if (this.JsonOldConDition.phapli != "") {
        $('#txtPhapLiIDRfs').val(this.JsonOldConDition.phapli);
        // }
        // if (this.JsonOldConDition.protype != "") {
        $('#txtPropertyType').val(this.JsonOldConDition.protype);
        // }

        // if (this.JsonOldConDition.giatu != "" && this.JsonOldConDition.giaden != "") {
        $('#txtGiaTu').val(this.JsonOldConDition.giatu);
        $('#txtGiaDen').val(this.JsonOldConDition.giaden);
        //}
        //else if (this.JsonOldConDition.gia != "") {
        $('#txtGia').val(this.JsonOldConDition.gia);
        // }

        // if (this.JsonOldConDition.dtttt != "" && this.JsonOldConDition.dtttd != "") {
        $('#txtDienTichTu').val(this.JsonOldConDition.dtttt);
        $('#txtDienTichDen').val(this.JsonOldConDition.dtttd);
        // }
        //else if (this.JsonOldConDition.dt != "") {
        $('#txtDienTich').val(this.JsonOldConDition.dt);
        //}

        // if (this.JsonOldConDition.dtnt != "" && this.JsonOldConDition.dtnd != "") {
        $('#txtDtnMinRfs').val(this.JsonOldConDition.dtnt);
        $('#txtDtnMaxRfs').val(this.JsonOldConDition.dtnd);
        // }
        //else if (this.JsonOldConDition.dtn != "") {
        $('#txtDTNRfs').val(this.JsonOldConDition.dtn);
        // }

        // if (this.JsonOldConDition.ktmtt != "" && this.JsonOldConDition.ktmtd != "") {
        $('#txtKtmtMinRfs').val(this.JsonOldConDition.ktmtt);
        $('#txtKtmtMaxRfs').val(this.JsonOldConDition.ktmtd);
        //}
        //else if (this.JsonOldConDition.ktmt != "") {
        $('#txtKTMTRfs').val(this.JsonOldConDition.ktmt);
        // }

        // if (this.JsonOldConDition.tab != "") 
        $('#txtTabRfs').val(this.JsonOldConDition.tab);

        /* dac tinh quang cao
        if ($('#txtIsImageIDRfs').val() != "" && $('#txtChinhChuRfs').val() != "") {
        $('#spnDtRfs').html('(BĐS có hình, Chính chủ)');
        }
        else if ($('#txtIsImageIDRfs').val() != "") {
        $('#spnDtRfs').html('(BĐS có hình)');
        }
        else if ($('#txtChinhChuRfs').val() != "") {
        $('#spnDtRfs').html('(Chính chủ)');
        }*/
    },
    ResDieuKienPhu: function () {


        $('#txtSuburb').val("");


        $('#txtEstate').val("");

        $('#txtWardIDRfs').val("");

        $('#txtStreetIDRfs').val("");

        $('#txtHuongIDRfs').val("");

        $('#txtPhapLiIDRfs').val("");

        $('#txtPropertyType').val("");

        $('#txtGiaTu').val("");
        $('#txtGiaDen').val("");

        $('#txtGia').val("");

        $('#txtDienTichTu').val("");
        $('#txtDienTichDen').val("");

        $('#txtDienTich').val("");

        $('#txtDtnMinRfs').val("");
        $('#txtDtnMaxRfs').val("");

        $('#txtDTNRfs').val("");

        $('#txtKtmtMinRfs').val("");
        $('#txtKtmtMaxRfs').val("");

        $('#txtKTMTRfs').val("");

    },
    ShowGiaText: function (val) {
        if (val < 1000)
            return (val + " Triệu");
        else {
            return (Math.round((val / 1000) * 100) / 100 + " Tỷ");
        }
    },
    SetDacTinhF: function (loai_, text_) {
        $('#txtTabRfs').val(loai_);
        $('#spnDtRfs').html(text_);
    },
    SetValHdf: function (_loai, _value) {
        switch (_loai) {
            case "suburb":
                if (this.CheckStringInListString(_value, $('#txtSuburb').val())) {
                    // remove
                    var arr1 = this.RemoveElementArr($('#txtSuburb').val(), _value);
                    $('#txtSuburb').val(arr1.join(','));
                }
                else {
                    // add	
                    var arr1 = this.AddElementArr($('#txtSuburb').val());
                    arr1.push(_value);
                    $('#txtSuburb').val(arr1.join(','));
                }
                $('#txtEstate').val("");
                $('#txtWardIDRfs').val("");
                $('#txtStreetIDRfs').val("");

                this.LoadEstate($('#txtStateID').val());
                this.LoadPx();
                this.LoadDuong();
                break;
            case "cbHomeClass":
                if (this.CheckStringInListString(_value, $('#txtPropertyType').val())) {
                    // remove
                    var arr1 = this.RemoveElementArr($('#txtPropertyType').val(), _value);
                    $('#txtPropertyType').val(arr1.join(','));
                }
                else {
                    // add	
                    var arr1 = this.AddElementArr($('#txtPropertyType').val());
                    arr1.push(_value);
                    $('#txtPropertyType').val(arr1.join(','));
                }
                break;
            case "cbMinPrice-cbMaxPrice":
                if ($('#txtGia').val() != _value) $('#txtGia').val(_value);
                else $('#txtGia').val("");
                $('#txtGiaTu').val("");
                $('#txtGiaDen').val("");
                $('#dtg').html("");
                $('#dtd').html("");
                break;
            case "dt":
                if ($('#txtDienTich').val() != _value) $('#txtDienTich').val(_value);
                else $('#txtDienTich').val("");
                $('#txtDienTichTu').val("");
                $('#txtDienTichDen').val("");
                break;
            case "dtn":
                if ($('#txtDTNRfs').val() != _value) $('#txtDTNRfs').val(_value);
                else $('#txtDTNRfs').val("");
                $('#txtDtnMinRfs').val("");
                $('#txtDtnMaxRfs').val("");
                break;
            case "ktmt":
                if ($('#txtKTMTRfs').val() != _value) $('#txtKTMTRfs').val(_value);
                else $('#txtKTMTRfs').val("");
                $('#txtKtmtMinRfs').val("");
                $('#txtKtmtMaxRfs').val("");
                break;
            case "cbEstate":
                if (this.CheckStringInListString(_value, $('#txtEstate').val())) {
                    // remove
                    var arr1 = this.RemoveElementArr($('#txtEstate').val(), _value);
                    $('#txtEstate').val(arr1.join(','));
                }
                else {
                    // add	
                    var arr1 = this.AddElementArr($('#txtEstate').val());
                    arr1.push(_value);
                    $('#txtEstate').val(arr1.join(','));
                }
                break;
            case "ward":
                if (this.CheckStringInListString(_value, $('#txtWardIDRfs').val())) {
                    // remove
                    var arr1 = this.RemoveElementArr($('#txtWardIDRfs').val(), _value);
                    $('#txtWardIDRfs').val(arr1.join(','));
                }
                else {
                    // add	
                    var arr1 = this.AddElementArr($('#txtWardIDRfs').val());
                    arr1.push(_value);
                    $('#txtWardIDRfs').val(arr1.join(','));
                }
                break;
            case "streetid":
                if (this.CheckStringInListString(_value, $('#txtStreetIDRfs').val())) {
                    // remove
                    var arr1 = this.RemoveElementArr($('#txtStreetIDRfs').val(), _value);
                    $('#txtStreetIDRfs').val(arr1.join(','));
                }
                else {
                    // add	
                    var arr1 = this.AddElementArr($('#txtStreetIDRfs').val());
                    arr1.push(_value);
                    $('#txtStreetIDRfs').val(arr1.join(','));
                }
                break;
            case "cbAspect":
                if (this.CheckStringInListString(_value, $('#txtHuongIDRfs').val())) {
                    // remove
                    var arr1 = this.RemoveElementArr($('#txtHuongIDRfs').val(), _value);
                    $('#txtHuongIDRfs').val(arr1.join(','));
                }
                else {
                    // add	
                    var arr1 = this.AddElementArr($('#txtHuongIDRfs').val());
                    arr1.push(_value);
                    $('#txtHuongIDRfs').val(arr1.join(','));
                }
                break;
            case "cbOwnerType":
                if (this.CheckStringInListString(_value, $('#txtPhapLiIDRfs').val())) {
                    // remove
                    var arr1 = this.RemoveElementArr($('#txtPhapLiIDRfs').val(), _value);
                    $('#txtPhapLiIDRfs').val(arr1.join(','));
                }
                else {
                    // add	
                    var arr1 = this.AddElementArr($('#txtPhapLiIDRfs').val());
                    arr1.push(_value);
                    $('#txtPhapLiIDRfs').val(arr1.join(','));
                }
                break;
            case "isimg":
                if ($('#txtIsImageIDRfs').val() != _value) $('#txtIsImageIDRfs').val(_value);
                else $('#txtIsImageIDRfs').val("");
                break;
            case "cchu":
                if ($('#txtChinhChuRfs').val() != _value) $('#txtChinhChuRfs').val(_value);
                else $('#txtChinhChuRfs').val("");
                break;
            default:
        }
        if ($('#hdfAdvanceSearch').val() == "refinesearch")
            this.PostRefineSearch(1);
    },
    SubmitRefineSearch: function () {
        if ($('#txtSuburb').val().split(',').length > 6) {
            alert("Bạn chọn quá nhiều quận/huyện, vui lòng chọn không quá 5");
            return false;
        }
        if ($('#txtEstate').val().split(',').length > 6) {
            alert("Bạn chọn quá nhiều dự án, vui lòng chọn không quá 5");
            return false;
        }

        //var suburb = "";
        //if (document.getElementById("txtSuburb").value != "")
        var suburb = "/d" + trim(document.getElementById("txtSuburb").value, ',');
        //        var propertyType = "";
        //        if (document.getElementById("txtPropertyType").value != "")
        //            propertyType = "&cbHomeClass=" + trim(document.getElementById("txtPropertyType").value, ',');
        var propertyType = "/e" + trim(document.getElementById("txtPropertyType").value, ',');

        // chi lam cho loai vnd
        var sOrder = "";
        var giaString = "";
        // format &cbMinPrice=500&cbMaxPrice=4000
        if (!checkFloat(trim($('#txtGiaTu').val(), ' ').replace(',', '.')) || !checkFloat(trim($('#txtGiaDen').val(), ' ').replace(',', '.'))) {
            alert("Giá phải là kiểu số");
            $('#txtGiaTu').focus();
            return false;
        }
        if ($('#txtGiaTu').val() != "" && $('#txtGiaDen').val() != "") {
            if (parseFloat(trim($('#txtGiaTu').val(), ' ').replace(',', '.')) >= parseFloat(trim($('#txtGiaDen').val(), ' ').replace(',', '.'))) {
                alert("Giá từ phải nhỏ hơn giá đến");
                $('#txtGiaTu').focus();
                return false;
            }

            sOrder = "/r-ranking";
            giaString = "/f" + $('#txtGiaTu').val() + "/g" + $('#txtGiaDen').val();
        }
        else if ($('#txtGia').val() != "") {
            sOrder = "/r-ranking";
            giaString = "/f" + $('#txtGia').val().split('-')[0] + "/g" + $('#txtGia').val().split('-')[1];
        }
        else {
            sOrder = "/r-ranking";
            giaString = "/f/g";
        }

        var strDienTich = "";
        if (!checkFloat(trim($('#txtDienTichTu').val(), ' ').replace(',', '.')) || !checkFloat(trim($('#txtDienTichDen').val(), ' ').replace(',', '.'))) {
            alert("Diện tích phải là kiểu số");
            $('#txtDienTichTu').focus();
            return false;
        }
        if ($('#txtDienTichTu').val() != "" || $('#txtDienTichDen').val() != "") {
            if (parseFloat(trim($('#txtDienTichTu').val(), ' ').replace(',', '.')) >= parseFloat(trim($('#txtDienTichDen').val(), ' ').replace(',', '.'))) {
                alert("Diện tích từ phải nhỏ hơn giá đến");
                $('#txtDienTichTu').focus();
                return false;
            }
            strDienTich = "/h" + $('#txtDienTichTu').val() + "/i" + $('#txtDienTichDen').val();
        }
        else if ($('#txtDienTich').val() != "") {
            strDienTich = "/h" + $('#txtDienTich').val().split('-')[0] + "/i" + $('#txtDienTich').val().split('-')[1];
        }
        else strDienTich = "/h/i";

        var strDuAn = "/k" + $('#txtEstate').val();

        //        strDuAn += "&ward=" + $('#txtWardIDRfs').val();
        //        strDuAn += "&streetid=" + $('#txtStreetIDRfs').val();
        //        strDuAn += "&cbAspect=" + $('#txtHuongIDRfs').val();
        //        strDuAn += "&cbOwnerType=" + $('#txtPhapLiIDRfs').val();
        strDuAn += "/l" + $('#txtWardIDRfs').val();
        //strDuAn += "/m" + $('#txtStreetIDRfs').val();
        strDuAn += "/m" + $('#txtHuongIDRfs').val();
        strDuAn += "/n" + $('#txtPhapLiIDRfs').val();

        var sDk = suburb + propertyType + giaString + strDienTich + strDuAn + sOrder;

        var proclass = $('#txtProClass').val();
        var transclass = $('#txtTranClass').val();
        var stateid = $('#txtStateID').val();
        var urlMota = "";
        var ss = "";
        
        if (transclass != "" && proclass != "") urlMota += transclass == "sale" ? "ban-" : "cho-thue-";
        else if (proclass == "") urlMota += transclass == "sale" ? "nha-dat-ban-" : "nha-dat-cho-thue-";

        if ($("#txtPropertyType").val() != "") urlMota += getKhongDauFromJsonArray3List(lstKieuBds, $("#txtPropertyType").val());
        else if (proclass != "") {
             ss = getKhongDauFromJsonArray2(lstPropertyClass, proclass);
            if (ss != "") urlMota += ss + "-";
        }

        if ($('#txtEstate').val() != "") {
            urlMota += getKhongDauFromJsonArray5List(lstDuAn, $('#txtEstate').val());            
        }
        if ($('#txtWardIDRfs').val() != "") urlMota += getKhongDauFromJsonArray3List(lstPhuong, $('#txtWardIDRfs').val());
        if ($("#txtSuburb").val() != "") urlMota += getKhongDauFromJsonArray3List(lstSuburb, $("#txtSuburb").val());

        if (stateid != "") {
             ss = getKhongDauFromJsonArray4(lstState, stateid);
            if (ss != "") urlMota += ss + "-";
        }
        if ($('#txtGiaTu').val() != "" && $('#txtGiaDen').val() != "") {
             ss = getKhongDauFromJsonArray3(lstGia, $('#txtGiaTu').val() + "-" + $('#txtGiaDen').val());
            if (ss != "") urlMota += ss + "-";
        }
        else if ($('#txtGia').val() != "") {
             ss = getKhongDauFromJsonArray3(lstGia, $('#txtGia').val());
             if (ss != "") urlMota += ss + "-";
             // kiem tra truong hop ng dung go vao, khong co trong du lieu co san
             else urlMota += giaTuEn + "-" + giaToiEn + "-";
        }

        if (urlMota != "") urlMota = urlMota.substring(0, urlMota.length - 1);

        if (proclass != "") {
            window.location = pathClient + urlMota + "/a-" + $('#txtTabRfs').val() + "/b-res-" + transclass + "-" + proclass + "/c" + stateid + sDk + "/?p=1";
        }
        else {
            stateid = "/c" + stateid;
            if (transclass != "") {
                window.location = pathClient + urlMota + "/a-" + $('#txtTabRfs').val() + "/b-res-" + transclass + stateid + sDk + "/?p=1";
            }
            //            else {
            //                window.location = pathClient + urlMota + "/a-rv/" + stateid + sDk + "/?p=1";
            //            }
        }
    },
    PostRefineSearch: function (p) {
        var proclass = $('#txtProClass').val();
        var transclass = $('#txtTranClass').val();
        var stateid = $('#txtStateID').val();

        if (proclass == "") {
            alert("Vui lòng chọn loại bất động sản!");
            $('#divLoaiKieuBDS').show();
            return false;
        }
        if (stateid == "") {
            alert("Vui lòng chọn tỉnh thành phố!");
            $('#divDropState').show();
            return false;
        }

        if ($('#txtSuburb').val().split(',').length > 6) {
            alert("Bạn chọn quá nhiều quận/huyện, vui lòng chọn không quá 5");
            return false;
        }
        if ($('#txtEstate').val().split(',').length > 6) {
            alert("Bạn chọn quá nhiều dự án, vui lòng chọn không quá 5");
            return false;
        }

        var suburb = "";
        if (document.getElementById("txtSuburb").value != "")
            suburb = trim(document.getElementById("txtSuburb").value, ',');
        var propertyType = "";
        if (document.getElementById("txtPropertyType").value != "")
            propertyType = trim(document.getElementById("txtPropertyType").value, ',');

        /*chi lam cho loai vnd*/

        var __ctlMain = document.getElementById("hdfCtlMst") != undefined ? $("#hdfCtlMst").val() + "_" : "";
        var _sOrder = $('#' + __ctlMain + 'hdOderBy').val() != undefined ? $('#' + __ctlMain + 'hdOderBy').val() : "";
        var _orderpricetype = $('#' + __ctlMain + 'hdPriceType').val() != undefined ? $('#' + __ctlMain + 'hdPriceType').val() : "";
        var _priceType = "";
        /* format &cbMinPrice=500&cbMaxPrice=4000*/
        var _giaTu = "";
        var _giaDen = "";
        /* fix cho cai loi gi k hieu tu nhien co HCM*/
        if (trim($('#txtGiaTu').val()) == "TP. Hồ Chí Minh") $('#txtGiaTu').val("");
        /*end*/
        if (!checkFloat(trim($('#txtGiaTu').val(), ' ').replace(',', '.')) || !checkFloat(trim($('#txtGiaDen').val(), ' ').replace(',', '.'))) {
            alert("Giá phải là kiểu số");
            $('#txtGiaTu').focus();
            return false;
        }
        if ($('#txtGiaTu').val() != "" && $('#txtGiaDen').val() != "") {
            if (parseFloat(trim($('#txtGiaTu').val(), ' ').replace(',', '.')) >= parseFloat(trim($('#txtGiaDen').val(), ' ').replace(',', '.'))) {
                alert("Giá từ phải nhỏ hơn giá đến");
                $('#txtGiaTu').focus();
                return false;
            }

            _sOrder = "prc";
            _orderpricetype = "1";
            _priceType = "VND";

            _giaTu = $('#txtGiaTu').val();
            _giaDen = $('#txtGiaDen').val();
        }
        else if ($('#txtGia').val() != "") {
            _sOrder = "prc";
            _orderpricetype = "1";
            _priceType = "VND";

            _giaTu = $('#txtGia').val().split('-')[0];
            _giaDen = $('#txtGia').val().split('-')[1];
        }

        var _dtttt = "";
        var _dtttd = "";
        if (!checkFloat(trim($('#txtDienTichTu').val(), ' ').replace(',', '.')) || !checkFloat(trim($('#txtDienTichDen').val(), ' ').replace(',', '.'))) {
            alert("Diện tích phải là kiểu số");
            $('#txtDienTichTu').focus();
            return false;
        }
        if ($('#txtDienTichTu').val() != "" && $('#txtDienTichDen').val() != "") {
            if (parseFloat(trim($('#txtDienTichTu').val(), ' ').replace(',', '.')) >= parseFloat(trim($('#txtDienTichDen').val(), ' ').replace(',', '.'))) {
                alert("Diện tích từ phải nhỏ hơn diện tích đến");
                $('#txtDienTichTu').focus();
                return false;
            }

            _dtttt = $('#txtDienTichTu').val();
            _dtttd = $('#txtDienTichDen').val();
        }
        else
            if ($('#txtDienTich').val() != "") {

                _dtttt = $('#txtDienTich').val().split('-')[0];
                _dtttd = $('#txtDienTich').val().split('-')[1];
            }

        var _page = "res";
        if (proclass != "") {
            if (proclass != 'com' && proclass != 'bus' && proclass != 'dev') {
                _page = "res";
            }
            else {
                _page = "res";
            }
        }

        var pars = {
            tab: $('#txtTabRfs').val(),
            pindex: p,
            rcc: $('#cbDisplay').val() != "" ? $('#cbDisplay').val() : "20",
            tck: _page + "-" + transclass + "-" + proclass,
            state: stateid,
            suburb: suburb,
            cbHomeClass: propertyType,
            cbMinPrice: _giaTu,
            cbMaxPrice: _giaDen,
            cbPriceType: _priceType,
            orderpricetype: _orderpricetype,
            orderby: _sOrder,
            dtt: _dtttt,
            dtd: _dtttd,
            //            dtnt: _dtnt,
            //            dtnd: _dtnd,
            //            ktmtt: _ktmtt,
            //            ktmtd: _ktmtd,
            cbEstate: $('#txtEstate').val(),
            ward: $('#txtWardIDRfs').val(),
            //streetid: $('#txtStreetIDRfs').val(),
            cbAspect: $('#txtHuongIDRfs').val(),
            cbOwnerType: $('#txtPhapLiIDRfs').val()
            /*             ,isimg: $('#txtIsImageIDRfs').val(),
            dtqc: $('#txtChinhChuRfs').val()*/
        };

        $('.snowBox').show();
        $('#dvPagingDefault').hide();
        var url = pathClientAjax + "services/misc.asmx/LoadListSearchBds";
        $.post(url, pars,
			function (data) {
			    NvgRefineSearch.BuildListPi(data);
			    NvgRefineSearch.LuuDieuKien();
			    $('.snowBox').hide();
			    NvgRefineSearch.AddHistoryEvent("lstbds", data, NvgRefineSearch.JsonOldConDition, $('#divRfsMain').html());
			}
		);
    },
    PostRefineSearchRsh: function (p) {
        var proclass = $('#txtProClass').val();
        var transclass = $('#txtTranClassRfs').val();
        var __ctlMain = document.getElementById("hdfCtlMst") != undefined ? $("#hdfCtlMst").val() + "_" : "";
        var _sOrder = $('#' + __ctlMain + 'hdOderBy').val() != undefined ? $('#' + __ctlMain + 'hdOderBy').val() : "";
        var _orderpricetype = $('#' + __ctlMain + 'hdPriceType').val() != undefined ? $('#' + __ctlMain + 'hdPriceType').val() : "";
        var _priceType = "VND";

        var _gt = "";
        var _gd = "";
        var _dtt = "";
        var _dtd = "";
        var _dtnt = "";
        var _dtnd = "";
        var _ktmtt = "";
        var _ktmtd = "";

        if (this.JsonOldConDition.giatu != "" && this.JsonOldConDition.giaden != "") {
            _gt = this.JsonOldConDition.giatu;
            _gd = this.JsonOldConDition.giaden;
        }
        else if (this.JsonOldConDition.gia != "") {
            _gt = this.JsonOldConDition.gia.split('-')[0];
            _gd = this.JsonOldConDition.gia.split('-')[1];
        }

        if (this.JsonOldConDition.dtttt != "" && this.JsonOldConDition.dtttd != "") {
            _dtt = this.JsonOldConDition.dtttt;
            _dtd = this.JsonOldConDition.dtttd;
        }
        else if (this.JsonOldConDition.dt != "") {
            _dtt = this.JsonOldConDition.dt.split('-')[0];
            _dtd = this.JsonOldConDition.dt.split('-')[1];
        }

        if (this.JsonOldConDition.dtnt != "" && this.JsonOldConDition.dtnd != "") {
            _dtnt = this.JsonOldConDition.dtnt;
            _dtnd = this.JsonOldConDition.dtnd;
        }
        else if (this.JsonOldConDition.dtn != "") {
            _dtnt = this.JsonOldConDition.dtn.split('-')[0];
            _dtnd = this.JsonOldConDition.dtn.split('-')[1];
        }

        if (this.JsonOldConDition.ktmtt != "" && this.JsonOldConDition.ktmtd != "") {
            _ktmtt = this.JsonOldConDition.ktmtt;
            _ktmtd = this.JsonOldConDition.ktmtd;
        }
        else if (this.JsonOldConDition.ktmt != "") {
            _ktmtt = this.JsonOldConDition.ktmt.split('-')[0];
            _ktmtd = this.JsonOldConDition.ktmt.split('-')[1];
        }

        var pars = {
            tab: this.JsonOldConDition.tab,
            pindex: p,
            rcc: $('#cbDisplay').val() != "" ? $('#cbDisplay').val() : "20",
            tck: "res" + "-" + transclass + "-" + proclass,
            state: this.JsonOldConDition.state,
            suburb: this.JsonOldConDition.suburb,
            cbHomeClass: this.JsonOldConDition.protype,
            cbMinPrice: _gt,
            cbMaxPrice: _gd,
            cbPriceType: _priceType,
            orderpricetype: _orderpricetype,
            orderby: _sOrder,
            dtt: _dtt,
            dtd: _dtd,
            dtnt: _dtnt,
            dtnd: _dtnd,
            ktmtt: _ktmtt,
            ktmtd: _ktmtd,
            cbEstate: this.JsonOldConDition.estate,
            ward: this.JsonOldConDition.ward,
            streetid: this.JsonOldConDition.street,
            cbAspect: this.JsonOldConDition.huong,
            cbOwnerType: this.JsonOldConDition.phapli
            /*             ,isimg: $('#txtIsImageIDRfs').val(),
            dtqc: $('#txtChinhChuRfs').val()*/
        };

        $('.snowBox').show();
        $('#dvPagingDefault').hide();
        var url = pathClientAjax + "services/misc.aspx?act=listsearchbds&d=" + (new Date()).getTime();
        $.post(url, pars,
			function (data) {
			    NvgRefineSearch.BuildListPiRsh(data, NvgRefineSearch.JsonOldConDition);
			    NvgRefineSearch.LuuDieuKien();
			    $('.snowBox').hide();
			    NvgRefineSearch.AddHistoryEvent("lstbds", data, NvgRefineSearch.JsonOldConDition, $('#divRfsMain').html());
			}
		);
    },
    gotoPagePostRfs: function (numberpage) {
        NvgRefineSearch.PostRefineSearch(numberpage);
    },
    gotoPagePostRfsRsh: function (numberpage, dieuKien_) {
        NvgRefineSearch.PostRefineSearchRsh(numberpage);
    },
    BuildListPiRsh: function (data, _dieuKien) {
        var _ctlMain = $('#hdfCtlMst').val() + "_";

        var count = parseInt(data.split("<--->")[2]);
        var result = data.split("<--->")[0];
        if (count == 0) {
            $("#" + _ctlMain + "DivPropertyList1").hide();
            $("#" + _ctlMain + "divMes").show();
            $("#" + _ctlMain + "divMes").html(result);
        }
        else {
            $("#" + _ctlMain + "divMes").hide();
            $("#" + _ctlMain + "DivPropertyList1").show();
            $("#" + _ctlMain + "DivPropertyList1").html(result);
        }
        //$("#" + _ctlMain + "DivPropertyList1").html(data.split("<--->")[0]);
        $("#" + _ctlMain + "divStringCondition").html(data.split("<--->")[1]);
        if ($('#txtTabRfs').val() == "mn")
            $("#" + _ctlMain + "ali1").html("<span>Mới nhất (" + count + ")</span>");
        //         if ($('#txtTabRfs').val() == "ag")
        //             $("#" + _ctlMain + "ali1").html("<span>Có tất cả (" + data.split("<--->")[2] + ")</span>");
        else if ($('#txtTabRfs').val() == "rv")
            $("#" + _ctlMain + "ali2").html("<span>Tất cả (" + count + ")</span>");
        else if ($('#txtTabRfs').val() == "cc")
            $("#" + _ctlMain + "ali4").html("<span>Chính chủ (" + count + ")</span>");
        else if ($('#txtTabRfs').val() == "ch") $("#" + _ctlMain + "ali5").html("<span>Có hình (" + count + ")</span>");

        var tps = (parseInt($("#hTotalRowsRfs").val()) / parseInt($("#hdfRecordCountRfs").val()) - parseInt(parseInt($("#hTotalRowsRfs").val()) / parseInt($("#hdfRecordCountRfs").val()))) > 0 ? ((parseInt(parseInt($("#hTotalRowsRfs").val()) / parseInt($("#hdfRecordCountRfs").val()))) + 1) : parseInt(parseInt($("#hTotalRowsRfs").val()) / parseInt($("#hdfRecordCountRfs").val()));

        if (tps < $("#hCurrentPageRfs").val())
            $("#hCurrentPageRfs").val(1);

        this.JsonOldConDition = _dieuKien;
        this.ResDieuKien();

        nvgPaging.DrawPageListBdsUsers(tps, $("#hCurrentPageRfs").val(), "dvPagingDefault", "NvgRefineSearch.gotoPagePostRfsRsh");
        /* kiem tra check cho rsh*/
        if (tps == 1) $('#dvPagingDefault').hide();
    },
    BuildListPi: function (data) {
        var _ctlMain = $('#hdfCtlMst').val() + "_";
        var count = parseInt(data.split("<--->")[2]);
        var result = data.split("<--->")[0];
        if (count == 0) {
            $("#" + _ctlMain + "DivPropertyList1").hide();
            $("#" + _ctlMain + "divMes").show();
            $("#" + _ctlMain + "divMes").html(result);
        }
        else {
            $("#" + _ctlMain + "divMes").hide();
            $("#" + _ctlMain + "DivPropertyList1").show();
            $("#" + _ctlMain + "DivPropertyList1").html(result);
        }
        $("#" + _ctlMain + "divStringCondition").html(data.split("<--->")[1]);
        if ($('#txtTabRfs').val() == "mn")
            $("#" + _ctlMain + "ali1").html("<span>Mới nhất (" + count + ")</span>");
        else if ($('#txtTabRfs').val() == "rv")
            $("#" + _ctlMain + "ali2").html("<span>Tất cả (" + count + ")</span>");
        else if ($('#txtTabRfs').val() == "cc")
            $("#" + _ctlMain + "ali4").html("<span>Chính chủ (" + count + ")</span>");
        else if ($('#txtTabRfs').val() == "ch") $("#" + _ctlMain + "ali5").html("<span>Có hình (" + count + ")</span>");

        var tps = (parseInt($("#hTotalRowsRfs").val()) / parseInt($("#hdfRecordCountRfs").val()) - parseInt(parseInt($("#hTotalRowsRfs").val()) / parseInt($("#hdfRecordCountRfs").val()))) > 0 ? ((parseInt(parseInt($("#hTotalRowsRfs").val()) / parseInt($("#hdfRecordCountRfs").val()))) + 1) : parseInt(parseInt($("#hTotalRowsRfs").val()) / parseInt($("#hdfRecordCountRfs").val()));

        if (tps < $("#hCurrentPageRfs").val())
            $("#hCurrentPageRfs").val(1);

        nvgPaging.DrawPageListBdsUsers(tps, $("#hCurrentPageRfs").val(), "dvPagingDefault", "NvgRefineSearch.gotoPagePostRfs");
        /* kiem tra check cho rsh*/
        if (tps == 1) $('#dvPagingDefault').hide();
    },
    HistoryChange: function (newLocation, historyData) {
        var historyMsg = (typeof historyData == "object" && historyData != null
		    ? historyStorage.toJSON(historyData)
		    : historyData
	    );

        if (historyMsg != null) {
            NvgRefineSearch.BuildListPiRsh(historyData.s1, historyData.s2);
            /*build lai leftsearch cua dieukien*/
            $('#divRfsMain').html(historyData.s3);
        }
    },
    AddHistoryEvent: function (key, data, dieukien, htmlLeftSearch_) {
        var jsonData = { s1: data, s2: dieukien, s3: htmlLeftSearch_ };

        dhtmlHistory.add(key, jsonData);
    },
    CheckPerTopAgent: function () {
        if ($('#' + $('#hdfCtlMst').val() + '_hdfCC_agt').val() == "0") {
            $('#rdoDTChinhChuF').removeAttr("checked");
            $('#rdoDTTatcaF').attr("checked", true);
            this.SetDacTinhF('rv', '(Tất cả BĐS)');

            nvgUtils.ShowNoteTopAgent();
        }
    },
    BindTopSearch: function () {
        var tranClass = $('#txtTranClass').val();
        var proClass = $('#txtProClass').val();
        var state = $('#txtStateID').val();
        var suburb = $('#txtSuburb').val();
        var gia = $('#txtGia').val();
        var duan = $('#txtEstate').val();
        var dientich = $('#txtDienTich').val();

        if (tranClass == 'sale') {
            NvgRefineSearch.ActiveTab('#liTabBan', '.tabBan');
            // LoadLoaiBDSFolTranClass('sale');SetValueQH('txtTranClass', 'sale');LoadGia();WriteTextCondition();
        }
        else if (tranClass == 'rent') {
            NvgRefineSearch.ActiveTab('#liTabChoThue', '.tabBan');
            //  LoadLoaiBDSFolTranClass('rent');SetValueQH('txtTranClass', 'rent');LoadGia();WriteTextCondition();
        }

        //        if (proClass != "") {
        //            $('#iptLoaiBDS').val($('#txtProClassText').val());
        //            $('#iptLoaiBDS').show();
        //            $('#hrfLoaiBDS').hide();
        //        }
        if (state != "") {
            //            $('#iptState').val($('#txtStateText').val());
            //            $('#iptState').show();
            //            $('#hrfState').hide();

            NvgRefineSearch.LoadQuanHuyen(state, $('#txtStateText').val());
            // gan lai vi qua ham nay, suburb bi clear
            $('#txtSuburb').val(suburb);
        }
        if (suburb != "") {
            LoadEstateFST(state);
        }
        //if (gia != "") {
        //            $('#iptGia').val(gia);
        //            $('#iptGia').show();
        //            $('#hrfGia').hide();
        //        }
        //        if (duan != "") {
        //            $('#iptEstate').val($('#txtEstateTextRfs').val());
        //            $('#iptEstate').show();
        //            $('#hrfEstate').hide();
        //        }
        //        if (dientich != "") {           
        //            $('#iptDienTich').val(dientich + " m2");
        //            $('#iptDienTich').show();
        //            $('#hrfDienTich').hide();
        //        }

        NvgRefineSearch.LoadLoaiBDSFolTranClassDefault($('#txtTranClass').val());
        ChonLoaiBDSNew1($('#txtProClass').val(), $('#txtProClassText').val());

        NvgRefineSearch.DefaultGiaTTDt();
        // these variables on formsearchtop.js
        strKieuBds = $('#txtProClassText').val();
        strQuanHuyen = $('#txtSuburbText').val();
        strGia = $('#txtGiaText').val();
        strDienTich = $('#txtDienTich').val();
        strEstate = $('#txtEstateTextRfs').val();

        NvgRefineSearch.WriteTextCondition();
    },
    ActiveTab: function (tab, classShow) {
        $('.boxSearch ul li').removeClass("current");
        $(tab).addClass("current");
        $('.boxSearch .contentSearch').hide();
        $(classShow).show();
    },
    WriteTextCondition: function () {
        var kqText = (strKieuBds != "" ? strKieuBds + " - " : (document.getElementById('txtProClassText').value != "" ? document.getElementById('txtProClassText').value + " - " : ""))
		     + (document.getElementById('txtTranClassText').value != "" ? document.getElementById('txtTranClassText').value + " - " : "")
		     + (document.getElementById('txtStateText').value != "" ? document.getElementById('txtStateText').value + " - " : "")
		     + (strQuanHuyen != "" ? strQuanHuyen + " - " : "")
		     + (strGia != "" ? strGia + " - " : "")
		     + (strDienTich != "" ? strDienTich + " - " : "")
		     + (strEstate != "" ? strEstate + " - " : "");

        if (strKieuBds != "" || document.getElementById('txtProClassText').value != "") {
            ShowTextTopSelect("hrfLoaiBDS", "iptLoaiBDS", strKieuBds != "" ? strKieuBds : (document.getElementById('txtProClassText').value != "" ? document.getElementById('txtProClassText').value : ""));
        }
        else {
            ShowTextTopSelect("hrfLoaiBDS", "iptLoaiBDS", "");
        }
        if (document.getElementById('txtStateText').value != "") {
            ShowTextTopSelect("hrfState", "iptState", (document.getElementById('txtStateText').value != "" ? document.getElementById('txtStateText').value : ""));
        }
        else {
            ShowTextTopSelect("hrfState", "iptState", "");
        }
        if (strQuanHuyen != "") {
            ShowTextTopSelect("hrfSuburb", "iptSuburb", (strQuanHuyen != "" ? strQuanHuyen : ""));
        }
        else {
            ShowTextTopSelect("hrfSuburb", "iptSuburb", "");
        }
        if (strGia != "") {
            ShowTextTopSelect("hrfGia", "iptGia", (strGia != "" ? strGia : ""));
        }
        else {
            ShowTextTopSelect("hrfGia", "iptGia", "");
        }
        if (strDienTich != "") ShowTextTopSelect("hrfDienTich", "iptDienTich", (strDienTich != "" ? strDienTich : ""));
        else ShowTextTopSelect("hrfDienTich", "iptDienTich", "");
        if (strEstate != "") ShowTextTopSelect("hrfEstate", "iptEstate", (strEstate != "" ? strEstate : ""));
        else ShowTextTopSelect("hrfEstate", "iptEstate", "");
    },
    DefaultGiaTTDt: function () {
        var tc = $('#txtTranClass').val();
        var pc = $('#txtProClass').val();

        var url = pathClientAjax + "services/formsearchhandler.asmx/DefaultGiaTTDt";
        $.post(url, { tc_: tc, pc_: pc },
            function (data) {
                lstState = data.tt.lst;
                NvgRefineSearch.TaoStateList(data.tt.lst, "divState", "txtStateID", "state");
                TaoList(data.dtich.lst, "divDienTich", "txtDienTich", "dientich");
                TaoList(data.gia.lst, "divGia", "txtGia", "gia");
            }
	    , 'json');
    },
    ShowMoreRfs: function (toggle) {
        if (toggle == true)
            $('.filterBox').toggle();
        else $('.filterBox').show();

        if ($('.filterBox').css("display") == 'none') {
            $('.filterLink').html("Lọc tìm kiếm");
        }
        else {
            $('.filterLink').html("Rút gọn");
        }
    }
};
/*
*	khoi tao rsh
*/
window.dhtmlHistory.create({
    toJSON: function (o) {
        return JSON.stringify(o);
    }, fromJSON: function (s) {
        return JSON.parse(s);
    }
});
window.onload = function () {
    /*initialize our DHTML history*/
    dhtmlHistory.initialize();
    /*subscribe to DHTML history change events*/
    dhtmlHistory.addListener(NvgRefineSearch.HistoryChange);
}
// this override function on formsearchtop.js to use for refine
 
function ChonLoaiBDSNew(id, textLoaiBDS_)
{
    document.getElementById('txtProClassText').value = textLoaiBDS_;
	document.getElementById('txtProClass').value = id;

 	$('#txtPropertyType').val("");
 	$('#txtPropertyTypeTextRfs').val("");
	
// this function on formsearchtop.js
    WriteTextCondition();
    $('#divLoaiKieuBDS').hide();

    if (id != "") {
        $('#iptLoaiBDS').val(textLoaiBDS_);
        $('#iptLoaiBDS').show();
        $('#hrfLoaiBDSs').hide();
    }

    NvgRefineSearch.listEstateFolState = [];
    // this function on formsearchtop.js
    LoadEstateFST($('#txtStateID').val());
    // NvgRefineSearch.LoadEstate($('#txtStateID').val());
	NvgRefineSearch.LoadKieuBDSRfs();
}
function ChonLoaiBDSNew1(id, textLoaiBDS_) {

    document.getElementById('txtProClassText').value = textLoaiBDS_;

    document.getElementById('txtProClass').value = id;

    if (id != "") {
        $('#iptLoaiBDSRfs').val(textLoaiBDS_);
        $('#iptLoaiBDSRfs').show();
        $('#hrfLoaiBDSRfs').hide();
    }

    $('#divLoaiKieuBDS').hide();

    NvgRefineSearch.listEstateFolState = [];
    /*
     *	neu co rsh thi load ajax default
     */
    if (historyStorage.hasKey("lstbds")) NvgRefineSearch.ResDieuKienPhu();
    NvgRefineSearch.LoadKieuBDSRfs();
}
function SetTextKieuBDS(divID)
{
	var strKieuBds="";
	document.getElementById("txtPropertyType").value="";	
	$('#'+divID+' input:checkbox').each(function (){
		if(this.checked==true)	
		{		
			document.getElementById("txtPropertyType").value+=this.value+",";
			strKieuBds+=this.title+", ";			
		}
	});		
	strKieuBds=strKieuBds.substring(0, strKieuBds.length-2);		
	
	$('#iptLoaiBDSRfs').val(strKieuBds);
	$('#iptLoaiBDSRfs').show();
	$('#hrfLoaiBDSRfs').hide();
}
function autoCompleteDiaDiemAdv(text) {
    if (text.length > 1) {
        var url = pathClientAjax + "services/formsearchhandler.asmx/GetDiaDiem";
        $.post(url, { txt: text },
		function (data) {
		    if (data.length > 0) {
		        $('#contentQuickSearch').html("");
		        var itemTplState = $.template("<li><a href=\"javascript:;\" onclick=\"setQhTtAdv(0,0,${tt},'${ttn}');\"><b>${ttn}</a></li>");
		        var itemTplAll = $.template("<li><a href=\"javascript:;\" onclick=\"setQhTtAdv(${qh},'${qhn}',${tt},'${ttn}');\"><b>${qhn}</b>, ${ttn}</a></li>");
		        for (var i = 0; i < data.length; i++) {
		            var item = data[i];
		            if (item.s1==0)$('#contentQuickSearch').append(itemTplState, { tt: item.s3, ttn: item.s4 });
		            else $('#contentQuickSearch').append(itemTplAll, { qh: item.s1, qhn: item.s2, tt: item.s3, ttn: item.s4 }); 
		        }
		        $(".tabBan .typeInBox .Dialog_0.hidDialog").show();
		    }
		    else $(".tabBan .typeInBox .Dialog_0.hidDialog").hide();
		}
	, 'json');
} else $('#contentQuickSearch').html("");
}
function setQhTtAdv(sbid, sbname, stid, stname) {
    $('#txtStateID').val("");
    $('#txtStateText').val("");
    $("#iptState").val("");
    $('#txtSuburb').val("");
    $("#iptSuburb").val("");   
    
    $('#txtStateID').val(stid);
    $('#txtStateText').val(stname);
    $(".typeInBox .Dialog_0.hidDialog").hide();

    $("#txtText").val("Bạn tìm nhà đất bán ở đâu?");
    $("#txtTextThue").val("Bạn tìm nhà đất cho thuê ở đâu?");

    if (parseInt(sbid) != 0) {
        if ($("#txtText").css("display") == 'block' || $("#txtText").css("display") == '' || $("#txtText").css("display") == 'inline')
            $("#txtText").val(sbname + ", " + stname);
        else $("#txtTextThue").val(sbname + ", " + stname);
        NvgRefineSearch.ShowTextTopSelect("hrfSuburb", "iptSuburb", sbname);
        $('#txtSuburb').val(sbid);
      //  NvgRefineSearch.SetValueF("divSuburb", sbid);
    }
    else {
        if ($("#txtText").css("display") == 'block' || $("#txtText").css("display") == '' || $("#txtText").css("display") == 'inline')
            $("#txtText").val(stname);
        else $("#txtTextThue").val(stname);
        NvgRefineSearch.ShowTextTopSelect("hrfSuburb", "iptSuburb", "");
    }
    NvgRefineSearch.ShowTextTopSelect("hrfState", "iptState", stname);
    NvgRefineSearch.LoadQuanHuyen(stid, stname);    
}